package com.cbs.android.module.shit.sample;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.cbs.android.component.application.activity.CBSActivity;
import com.cbs.android.component.applicationutils.network.ErrorResponse;
import com.cbs.android.component.toast.Toast;
import com.cbs.android.module.user.user.UserModule;
import com.cbs.android.module.user.user.entity.User;
import com.cbs.android.module.user.user.handler.ModuleHandler;
import com.google.gson.Gson;

public class MainActivity extends CBSActivity {
    private static final String TAG = MainActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void login(View view) {
        UserModule.login("13382850839", "123456", new ModuleHandler<User>() {
            @Override
            public void onSuccess(User user) {
                Toast.show("login success");
            }

            @Override
            public void onFailure(int i, String s) {
                ErrorResponse errorResponse = new Gson().fromJson(s, ErrorResponse.class);
                Toast.show("login failed: " + errorResponse.getErrorMsg());
            }

            @Override
            public void onException(Exception e) {
                Toast.show("login failed");
            }
        });
    }

    public void logout(View view) {
        UserModule.logout();
    }

    public void open(View view) {
        Intent intent = new Intent(this, MainActivity2.class);
        startActivity(intent);
    }
}

